package com.zzw.service;

import com.zzw.entity.SysFunPermission;
import com.zzw.entity.SysRole;
import com.zzw.mapper.dao.SysFunPermissionMapper;
import com.zzw.mapper.dao.SysRoleMapper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@CacheConfig(cacheNames = "sysRoleService")
public class SysRoleService {
    private SysRoleMapper sysRoleMapper;

    @CachePut(key = "#p0.id", unless = "#result eq null")  //#p0表示第一个参数
    public SysRole insertSysRole(SysRole sysRole) {
        sysRoleMapper.insert(sysRole);
        return sysRole;
    }

    @CachePut(key = "#p0.id", unless = "#result eq null")  //#p0表示第一个参数
    public SysRole updateSysRole(SysRole sysRole) {
        sysRoleMapper.updateByPrimaryKey(sysRole);
        return sysRole;
    }

    @CacheEvict(key = "#p0.id")  //删除缓存名称为userCache,key等于指定的id对应的缓存
    public int deleteSysRole(SysRole sysRole) {
        return sysRoleMapper.delete(sysRole);
    }

    @Cacheable(key = "#p0.id", unless = "#result eq null")  //#p0表示第一个参数
    public SysRole selectSysRole(SysRole sysRole) {
        return sysRoleMapper.selectOne(sysRole);
    }

    @CacheEvict(allEntries = true)
    public int deleteAll() {
        return sysRoleMapper.delete(null);
    }

    @CacheEvict(allEntries = true)
    public int deleteByIds(String ids) {
        return sysRoleMapper.deleteByIds(ids);
    }
}
